// 导入全局环境变量的第三方库:dotenv
import dotenv from "dotenv";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// 使用 dotenv 加载项目根目录下的 .env 文件
dotenv.config();
// 加载公钥私钥
const PRIVATE_KEY = fs.readFileSync(
  path.resolve(__dirname, "./keys/rsa_private_key.pem")
);
const PUBLICK_KEY = fs.readFileSync(
  path.resolve(__dirname, "./keys/rsa_public_key.pem")
);
const UPLOAD_DIR = path.join(__dirname, "../../uploads");

// 导出全局环境变量对象
export default {
  APP_PORT: process.env.APP_PORT || "",
  APP_HOST: process.env.APP_HOST || "",
  MYSQL_HOST: process.env.MYSQL_HOST || "",
  MYSQL_PORT: process.env.MYSQL_PORT || "",
  MYSQL_DATABASE: process.env.MYSQL_DATABASE || "",
  MYSQL_USER: process.env.MYSQL_USER || "",
  MYSQL_PASSWORD: process.env.MYSQL_PASSWORD || "",
  UPLOAD_DIR,
  PRIVATE_KEY,
  PUBLICK_KEY,
};
